﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace GreenPepperTest
{
    class HomeSecuritySystem
    {
        private ICollection<MotionDetector> motionDetectors;
        private ICollection<GlassDetector> glassDetectors;

        public ICollection<MotionDetector> MotionDetectors
        {
            get
            {
                return motionDetectors;
            }
        }

        public ICollection<GlassDetector> GlassDetectors
        {
            get
            {
                return glassDetectors;
            }
        }

        public HomeSecuritySystem()
        {
            motionDetectors = new List<MotionDetector>();
            glassDetectors = new List<GlassDetector>();
        }

        public void AddMotionDetector(MotionDetector det)
        {
            motionDetectors.Add(det);
        }

        public void CreateMovementAt(string loc)
        {
            foreach (MotionDetector det in motionDetectors)
            {
                if (det.Location.Equals(loc))
                {
                    det.TripAlarm();
                    return;
                }
            }
        }

        public bool IsAlarmTrippedAt(string loc)
        {
            foreach (MotionDetector det in motionDetectors)
            {
                if (det.Location.Equals(loc))
                {
                    return det.IsAlarmTripped;
                }
            }
            return false;
        }

        public bool IsAlarmOn(string loc)
        {
            foreach (MotionDetector det in motionDetectors)
            {
                if (det.Location.Equals(loc))
                {
                    return det.IsOn;
                }
            }
            return false;
        }

        public void ResetMotionDetectorAt(string loc)
        {
            foreach (MotionDetector det in motionDetectors)
            {
                if (det.Location.Equals(loc))
                {
                    det.ResetAlarm();
                    return;
                }
            }
        }

        public int GetNumberOfMotionDetectors()
        {
            return motionDetectors.Count;
        }
    }
}
